/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.sgs.dao;

import br.com.sgs.entity.Processo;
import java.util.List;
import javax.persistence.Query;

/**
 *
 * @author Eric
 */
public class DAOProcesso extends AbstractDAO implements IDAOProcesso{
    
    public DAOProcesso(){
        super();
    }
    
    @Override
    public Processo findProcessoById(int idprocesso) {
         try {

            Query q = em.createQuery("SELECT p FROM Processo p WHERE p.id = :idprocesso");
            q.setParameter("idprocesso", idprocesso);
            return (Processo) q.getSingleResult();

        } catch (Exception e) {
            System.err.println("Erro no findProcessoById");
            return null;
        }
    }

    @Override
    public List<Processo> findProcesso() {
        try {

            Query q = em.createQuery("SELECT p FROM Processo p");
            return q.getResultList();

        } catch (Exception e) {
            System.err.println("Erro no findProcesso");
            e.printStackTrace();
            return null;
        }
    }
    
    @Override
    public List<Processo> findProcessoByOrientacao(String orientacao) {
        try {

            Query q = em.createQuery("SELECT p FROM Processo p WHERE UPPER(p.orientacao) LIKE :orientacao");
            q.setParameter("orientacao", "%"+orientacao+"%");
            
            return q.getResultList();

        } catch (Exception e) {
            System.err.println("Erro no findModeloByDescricao");
            e.printStackTrace();
            return null;
        }
    }
}
